package com.lwt.controller;

import com.lwt.bean.Department;
import com.lwt.bean.JsonMsg;
import com.lwt.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author Li Weitong
 * @Date 2021/1/11 20:54
 */

@Controller
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 返回查询出的所有部门信息的json字符串给浏览器
     * @return
     */
    @RequestMapping("/depts")
    @ResponseBody
    public JsonMsg getDepts(){
        System.out.println("向服务器发送了一次ajax请求");

        List<Department> list = departmentService.queryDepts();
        System.out.println(list);
        return JsonMsg.success().add("depts",list);
    }
}
